<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<style type="text/css">
			#index>.loadingImg {
				width: 100vw;
				height: 100vh;
				vertical-align: middle;
				background-image: url(images/total.png);
				background-repeat: no-repeat;
				background-size: 100% 100%;
				background-position: center;
			}
			
			.skip {
				position: absolute;
				top: 20px;
				right: 20px;
				font-size: 14px;
				color: #fff;
				border-radius: 50px;
				background: rgba(0, 0, 0, 0.3);
				line-height: 22px;
				padding: 2px 14px;
				text-align: center;
			}
		</style>
	</head>

	<body>
		<div id="index" v-cloak>
			<div class="loadingImg" :style="{backgroundImage : 'url(' + imgCommonUrl+checkUrl.img + ')'}" @tap='openurl(checkUrl)'></div>
			<div class="skip" @tap="skipOpen">跳过{{skip}}</div>
		</div>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/libs/zepto.js"></script>
		<script src="../../js/libs/vue.js"></script>
		<script src="../../js/common.js"></script>
		<script type="text/javascript">
			mui.init()
			mui.plusReady(function() {
				var clock = mui.back
				var self = plus.webview.currentWebview();
				self.setStyle({
					'popGesture': 'none'
				});
				mui.back = function() {}
				var home = new Vue({
					el: '#index',
					data: {
						imgCommonUrl: common.imageUrl,
						checkUrl: self.preate.imgs[randomNum(0, self.preate.imgs.length - 1)],
						skip: 2
					},
					methods: {
						openurl: function(data) {
							if(data.url) {
								mui.openWindow({
									id: "../mask/nesting.html",
									url: '../mask/nesting.html',
									extras: {
										url: data.url
									}
								});
							}
						},
						skipOpen: function() {
							platform()
							self.close()
						}
					}
				})
				setTimeout(down, 1000)

				function down() {
					if(home.skip <= 0) {
						platform()
						if(plus.webview.getWebviewById('../mask/nesting.html')) {
							self.close('none')
						} else {
							self.close()
						}
						return
					}
					home.skip--
						setTimeout(down, 1000)
				}
				//生成从minNum到maxNum的随机数
				function randomNum(minNum, maxNum) {
					switch(arguments.length) {
						case 1:
							return parseInt(Math.random() * minNum + 1, 10);
							break;
						case 2:
							return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
							break;
						default:
							return 0;
							break;
					}
				}

				function platform() {
					var versions = mui.os.ios ? 2 : 1
					common.ajax('/p/userhome/getVersion', {
						platform: versions
					}, function(data) {
						if(data.code == 1) {
							localStorage.removeItem('toupdate')
							plus.runtime.getProperty(plus.runtime.appid, function(inf) {
								var wgtVer = inf.version;
								if(data.data.newVer > wgtVer) {
									var wp = plus.webview.create('toupdate.html', 'html/mask/toupdate.html', {
										scrollIndicator: 'none',
										scalable: false,
										popGesture: 'none',
										background: 'transparent'
									}, {
										preate: data.data
									})
									wp.show('fade-in');
								}
							});
						} else {
							localStorage.setItem('toupdate', true)
						}
					}, true, 'get')
				}

			})
		</script>
	</body>

</html>